class Solution {
    public:
        vector<int> findOrder(int numProject, vector<vector<int> >& groups) {
                    vector<vector<int>> edg(numProject);
                            vector<int> in(numProject);
                             
                                     for(auto& e : groups)
                                             {
                                                             int a = e[0], b = e[1];
                                                                         edg[b].push_back(a); // b->a
                                                                                     in[a]++;
                                             }
                                              
                                                      queue<int> q;
                                                              for(int i = 0; i < numProject; ++i)
                                                                      {
                                                                                      if(in[i] == 0)
                                                                                                      q.push(i);
                                                                      }
                                                                              vector<int> ret;
                                                                                      while(q.size())
                                                                                              {
                                                                                                              int x = q.front();
                                                                                                                          q.pop();
                                                                                                                                      ret.push_back(x);
                                                                                                                                                  for(auto& e : edg[x])
                                                                                                                                                              {
                                                                                                                                                                                  if(--in[e] == 0)
                                                                                                                                                                                                      q.push(e);
                                                                                                                                                              }
                                                                                              }
                                                                                                      // if(ret.size() == numProject)
                                                                                                              //     return ret;
                                                                                                                      // return {};
                                                                                                                              return ret.size()== numProject ? ret : (ret.clear(), ret);
        }
};
                                                                                                                                                              }
                                                                                              }
                                                                      }
                                             }
        }
}